{{template "admin/header.html"}}
<title>页面模板 - GPRESS</title>
<style>
	table {
		width: 100%;
		flex: 1;
		overflow: auto;
	}
	table td {
	width: fit-content;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	word-break: break-all;
	vertical-align: middle !important;
	max-width: 200px;
}
</style>
{{template "admin/bodystart.html"}}
<div class="layui-card layui-panel" style="height: 100%;">
	<div class="layui-card-body">
		<form id="listForm" action="{{basePath}}admin/{{.UrlPathParam}}/list" method="GET">
			<input type="hidden" id="pageNo" name="pageNo" value="{{.Page.PageNo}}">
			<div class="layui-input-group">
				<input type="text" name="q" placeholder="搜索" class="layui-input">
				<div class="layui-input-split layui-input-suffix" style="cursor: pointer;">
					<i class="layui-icon layui-icon-search"></i>
				</div>
				<div class="layui-input-suffix">
					<a href="{{basePath}}admin/{{.UrlPathParam}}/save" class="layui-btn layui-bg-blue">新增模板</a>
				</div>
			</div>
		</form>
		<table class="layui-table" id="table_list" lay-filter="parse-table-list">
			<thead>
				<tr>
					<th>ID</th>
					<th>模板名称</th>
					<th>模板路径</th>
					<th>更新时间</th>
					<th>排序</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
				<!-- 循环所有的数据 -->
				{{ range $i,$v := .Data }}
				<tr>
					<!-- 获取每一列的值 -->
					<td title="{{ .Id }}"><a href="{{basePath}}admin/{{$.UrlPathParam}}/look?id={{$v.Id}}"> {{ .Id }} </a></td>
					<td title="{{ .Name }}"> {{ .Name }}</td>
					<td title="{{ .TemplatePath }}"> {{ .TemplatePath }}</td>
					<td> {{ .UpdateTime }}</td>
					<td> {{ .SortNo }}</td>
					<td>
						<button type="button" class="layui-btn layui-btn-primary layui-btn-xs" title="编辑">
							<a href="{{basePath}}admin/{{$.UrlPathParam}}/update?id={{$v.Id}}">
								<i class="layui-icon layui-icon-edit"></i>
							</a>
						</button>
						<button type="button" class="layui-btn layui-btn-primary layui-btn-xs"
							onclick="deleteFunc('{{$v.Id}}','{{basePath}}admin/{{$.UrlPathParam}}/delete');" title="删除">
							<i class="layui-icon layui-icon-delete"></i>
						</button>
					</td>
				</tr>
				{{end }}
			</tbody>
		</table>
		<div id="div-list-page"></div>
	</div>
</div>
{{template "admin/bodyend.html"}}

<script>
	var layer;
	var $;
	layui.use(function () {
		//var table = layui.table;
		layer = layui.layer;
		$ = layui.jquery;
		var laypage = layui.laypage;

		// 普通用法
		laypage.render({
			elem: 'div-list-page',
			count: "{{.Page.TotalCount}}",
			limit: "{{.Page.PageSize}}",
			curr: "{{.Page.PageNo}}",
			theme: '#1890ff',
			layout: ['prev', 'page', 'next', 'count', 'skip'], // 功能布局
			jump: function (obj) {
				let pageNo = document.getElementById("pageNo").value - 0;
				if (pageNo != obj.curr) {
					document.getElementById("pageNo").value = obj.curr;
					document.getElementById("listForm").submit();
				}
			}
		});
	});

	function deleteFunc(id, url) {
		layer.confirm('确认删除?', {
			icon: 3,
			title:"确认",
			btn: ['确定', '取消'] //按钮
		}, function () {
			$.ajax({
				type: 'post',
				url: url, 
				data: { "id": id },
				success: function (res) {
					if (res.statusCode === 1) {
						layer.msg("删除成功",function(){
							location.reload();
						});
					}
				}
			});
		});
	}

</script>